﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;

namespace YJKColumnModify.ConnectColumnBream
{
	internal class Collider
	{
		public static List<Element> GetElementByCollision(Element tagElement, Autodesk.Revit.DB.Document doc)
		{
			List<Element> list = new List<Element>();
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc);
			ElementIntersectsElementFilter elementIntersectsElementFilter = new ElementIntersectsElementFilter(tagElement, false);
			filteredElementCollector.WherePasses(elementIntersectsElementFilter);
			foreach (Element item in filteredElementCollector)
			{
				list.Add(item);
			}
			return list;
		}

		public static List<Element> GetElementByCollision(Element tagElement, BuiltInCategory needElement, Autodesk.Revit.DB.Document doc)
		{
			List<Element> list = new List<Element>();
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc);
			ElementIntersectsElementFilter elementIntersectsElementFilter = new ElementIntersectsElementFilter(tagElement);
			filteredElementCollector.WherePasses(elementIntersectsElementFilter);
			foreach (Element element in filteredElementCollector)
			{
                if (element.Category.Id.IntegerValue == (int)needElement)
				{
					list.Add(element);
				}
			}
			return list;
		}

		public static List<Element> GetElementByCollision(Element tagElement, Predicate<Element> inPredicate, Autodesk.Revit.DB.Document doc)
		{
			List<Element> list = new List<Element>();
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc);
			ElementIntersectsElementFilter elementIntersectsElementFilter = new ElementIntersectsElementFilter(tagElement, false);
			filteredElementCollector.WherePasses(elementIntersectsElementFilter);
			foreach (Element element in filteredElementCollector)
			{
				if (inPredicate(element))
				{
					list.Add(element);
				}
			}
			return list;
		}

		public static List<Element> GetElementByCollision(Solid tagSolid, Autodesk.Revit.DB.Document doc)
		{
			List<Element> list = new List<Element>();
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc);
			ElementIntersectsSolidFilter elementIntersectsSolidFilter = new ElementIntersectsSolidFilter(tagSolid, false);
			filteredElementCollector.WherePasses(elementIntersectsSolidFilter);
			foreach (Element item in filteredElementCollector)
			{
				list.Add(item);
			}
			return list;
		}

		public static List<Element> GetElementByCollision(Solid tagSolid, BuiltInCategory needElement, Autodesk.Revit.DB.Document doc)
		{
			List<Element> list = new List<Element>();
			if (tagSolid == null)
			{
				return list;
			}
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc);
			ElementIntersectsSolidFilter elementIntersectsSolidFilter = new ElementIntersectsSolidFilter(tagSolid, false);
			filteredElementCollector.WherePasses(elementIntersectsSolidFilter);
			foreach (Element element in filteredElementCollector)
			{
                if (element.Category.Id.IntegerValue == (int)needElement)
				{
					list.Add(element);
				}
			}
			return list;
		}

		public static List<Element> GetElementByCollision(Solid tagSolid, Predicate<Element> inPredicate, Autodesk.Revit.DB.Document doc)
		{
			List<Element> list = new List<Element>();
			if (tagSolid == null)
			{
				return list;
			}
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc);
			ElementIntersectsSolidFilter elementIntersectsSolidFilter = new ElementIntersectsSolidFilter(tagSolid, false);
			filteredElementCollector.WherePasses(elementIntersectsSolidFilter);
			foreach (Element element in filteredElementCollector)
			{
				if (inPredicate(element))
				{
					list.Add(element);
				}
			}
			return list;
		}
	}
}
